const qs = require('qs')
const linkRTC = function (url, params, config = {}, own) {
  const ws = new WebSocket(`ws://${url}?${qs.stringify(params)}`)

  ws.onmessage = e => {
    console.log('message', e)
  }
  ws.onclose = (e, i) => {
    console.log('close', e)
  }

  return new Promise((resolve, reject) => {
    ws.onopen = e => {
      console.log('open', e)
      resolve(ws)
    }
    ws.onerror = err => {
      reject(err)
    }
  })
}
export default linkRTC
